package com.baiytfp.hf.HFDataExchange.action.controller.view;

import com.baiytfp.hf.baiytfp.framework.base.BaseController;
import com.baiytfp.hf.baiytfp.hfutils.HFDBHelper;
import com.baiytfp.hf.baiytfp.hfutils.HFRequest;
import com.baiytfp.hf.HFDataExchange.common.base.anotation.Auth;
import com.baiytfp.hf.HFDataExchange.common.model.base.TableName;
import com.baiytfp.hf.HFDataExchange.common.model.table.Position;
import com.baiytfp.hf.HFDataExchange.common.model.table.Position_type;
import com.baiytfp.hf.HFDataExchange.common.model.table.Role;
import com.baiytfp.hf.HFDataExchange.common.model.table.User_role;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


@Controller
@RequestMapping("/view/position")
public class PositionVController extends BaseController {



	@RequestMapping("/posilist")
	@Auth(checkMenu=true)
	public ModelAndView posilist(HttpServletRequest request,HttpServletResponse response) throws Exception {

		ModelAndView mav = new ModelAndView();

		return mav;
	}

	@RequestMapping("/posiedit")
	@Auth(checkMenu=true)
	public ModelAndView posiedit(HttpServletRequest request, HttpServletResponse response) throws Exception {

		String key = HFRequest.getIstance().getString(request, "itemid");

		//已有角色
		List<Position_type> list_posi_type = HFDBHelper.list(TableName.POSITION_TYPE, "", Position_type.class, null);

		if(!"".equals(key) && !"0".equals(key)){	//查看
			Position itemObj = HFDBHelper.read(TableName.POSITION, " where id=? ", Position.class, key);

			ModelAndView mav = new ModelAndView();
			mav.addObject("item_obj", itemObj);

			mav.addObject("list_posi_type", list_posi_type);
			mav.addObject("is_read", HFRequest.getIstance().getString(request, "is_read", ""));

			return mav;

		}else{	//新增

			ModelAndView mav = new ModelAndView();

			mav.addObject("list_posi_type", list_posi_type);
			mav.addObject("item_obj", null);

			return mav;
		}

	}


	@RequestMapping("/typelist")
	@Auth(checkMenu=true)
	public ModelAndView typelist(HttpServletRequest request,HttpServletResponse response) throws Exception {

		ModelAndView mav = new ModelAndView();

		return mav;
	}

	@RequestMapping("/typeedit")
	@Auth(checkMenu=true)
	public ModelAndView typeedit(HttpServletRequest request, HttpServletResponse response) throws Exception {

		String key = HFRequest.getIstance().getString(request, "itemid");

		if(!"".equals(key) && !"0".equals(key)){	//查看
			Position_type itemObj = HFDBHelper.read(TableName.POSITION_TYPE, " where id=? ", Position_type.class, key);

			ModelAndView mav = new ModelAndView();
			mav.addObject("item_obj", itemObj);

			mav.addObject("is_read", HFRequest.getIstance().getString(request, "is_read", ""));

			return mav;

		}else{	//新增

			ModelAndView mav = new ModelAndView();

			mav.addObject("item_obj", null);

			return mav;
		}

	}

}
